﻿#include "GameMenu.h"

 CGameMenu* CGameMenu::instance;//khoi tao bien static
 CGameMenu::CGameMenu()
 {
	 _choose=Start;
 }
 CGameMenu::~CGameMenu()
 {

 }
 //Singleton 
 CGameMenu* CGameMenu::SetInstance()
 {
	 if (instance==NULL)
	 {
		instance =new CGameMenu();
	 }
	 return instance;
 }
 bool CGameMenu::Game_Init()
 {
	 //Load ảnh nền 
	 _background=_gr->LoadSurface("Images\\Logo.png",D3DCOLOR_ARGB(255,0,0,0));
	 //Load sprite menu
	 _spriteChose=new CSprites("Images\\Menu.png",168,28,3,1);
	 //Load cái file ầm thanh
	_sound->AddFile(OTHERFILES,"MenuChange","Sounds\\MenuChange.mp3",BASS_MUSIC_RAMPS);
	_sound->AddFile(OTHERFILES,"BackSound","Sounds\\BackSound.wav",BASS_MUSIC_RAMPS);
	 return true;
 }
 void CGameMenu::Game_Run(HWND hwnd,DWORD tickPerFrame)
 {
	 //update sau môt khoảng thời gian
	 Game_Update(tickPerFrame);
	 //Bắt đầu vẽ
	 _gr->BeginRender(hwnd,_background);
	 //Tùy theo biết chọn để tính frame được hiện ra trong sprite menu
	 _spriteChose->Render(582,475+(_choose*28),_choose);
	 _gr->EndRender();
 }
 void CGameMenu::Game_Update(DWORD tickPerFrame)
 {
	 //Hàm bắt phím
	 _dxInput->Pool_Keyboard();
	 //Nhạc nền
	// _sound->Play("BackSound",false);
	 //Các sự kiệm khi lick vào phím
	 if (_dxInput->OnKeyDown(DIK_DOWN))
	 {
		 if (_choose==Start)
		 {
			 _choose=Load;
			 _sound->Play("MenuChange",false);
			 return;
		 }
		 if (_choose==Load)
		 {
			 _choose=Quit;
			 _sound->Play("MenuChange",false);
			 return;
		 }
	 }
	 if (_dxInput->OnKeyDown(DIK_UP))
	 {
		 if (_choose==Quit)
		 {
			 _choose=Load;
			 _sound->Play("MenuChange",false);
			 return;
		 }
		 if (_choose==Load)
		 {
			 _choose=Start;
			 _sound->Play("MenuChange",false);
			 return;
		 }
	 }
	 if(_dxInput->OnKeyDown(DIK_RETURN))
	 {
		 switch(_choose)
		 {
		 case Start:
			 CGameState::state=GameState::Play;
			 return;
		 case Load:
			 CGameState::state=GameState::LoadGame;
			 return;
		 case Quit:
			 PostQuitMessage(0);
			 return;
		 }

	 }
 }
 void CGameMenu::Game_Reset()
 {
	 Game_End();
 }
 void CGameMenu::Game_End()
 {
	 //Giải phóng đối tượng MenuGame
	 instance=NULL;
 }